<?php

namespace App\Http\Models\Admin;

use App\Http\Controllers\Admin\Common;

class Node extends Base
{
    protected $table="node";

	public function mkMenu() {
		$rules = Role::where('id',session('user_info')['role_id'])->value('rules');
		if($rules == '*'){
			$where = [];
		}else{
			$rules = explode(',',$rules);
			$where = function($query)use($rules){
				foreach($rules as $v){
					$query->orWhere("id",$v);
				}
			};
		}
		$Menu = $this::where('is_menu',1)->where($where)->orderBy('sort','asc')->get()->toArray();
		$common = new Common;
		return $common->getTree($Menu,false);
	}
}
